/*
 * @Author: cmd
 * @we_chat: cmd_develop
 * @qq群: 790373986
 * @LastEditors: cmd
 * @Description: 
 * @Date: 2019-03-20 22:45:09
 * @LastEditTime: 2019-03-20 22:49:00
 */

const {ccclass, property} = cc._decorator;

@ccclass
export default class loading extends cc.Component {

    @property(cc.ProgressBar)
    bar:cc.ProgressBar = null;

    @property(cc.Node)
    scene_change_shader:cc.Node = null;

    onLoad () {   
        //1.预先加载预制体和音乐文件
        orc.orc_win.preload();
        orc.orc_sound.preload();    
        this.normal_enter();  
    }

    async normal_enter(){       
        // //1.登录
        // let body = [];         
        // let net_login:any = JSON.parse(await orc.orc_net.http_post(orc.orc_url_config.game_login,false,body));
        // console.log('net_login',net_login);
        // if(net_login.code == 200)
        // {
        //     orc.orc_data.memory_data.user_info = net_login.data.info;
        //     this.node.parent.getChildByName('scene_change').getComponent('scene_change').loadScene();            
        // }       
        // else
        // {
        //     orc.component_manager.show_alert_tips('网络异常');
        // }

        this.scene_change('game_main');
    }
   

   
   
    /**
     * 
     * @param dir_scene 准备跳去那个场景     
     */
    async scene_change(dir_scene){
        this.bar.progress = 0;

        //加载下一个场景需要的资源         
        var asd = function (completedCount,totalCount,item) {
            console.log("completedCount:" + completedCount + ",totalCount:" + totalCount );
            var per = completedCount / totalCount;            
            this.bar.progress = per;            
        }.bind(this);
        
        cc.director.preloadScene(dir_scene, asd, ()=>{
            console.log('加载完成'); 
            this.scene_change_shader.getComponent('scene_change').loadScene(); 
        });
        
    }    
}
